Add Spring Cloud Stream retry support to ServiceBus Binder#47149
Add Spring Cloud Stream retry support to ServiceBus Binder#47149
Conversation
Implement support for Spring Cloud Stream's consumer retry properties: - back-off-initial-interval - back-off-max-interval - back-off-multiplier - max-attempts Changes: - Added RetryTemplate support to ServiceBusInboundChannelAdapter - Created RetryTemplate based on consumer properties in ServiceBusMessageChannelBinder - Wrapped message sending with retry logic when maxAttempts > 1 - Added comprehensive tests for retry behavior - Maintained backward compatibility (no retry when maxAttempts = 1) Co-authored-by: saragluna <31124698+saragluna@users.noreply.github.com>
- Updated CHANGELOG.md for both ServiceBus binder and integration modules - Created comprehensive RETRY_CONFIGURATION.md guide - Documented configuration properties, behavior, examples, and best practices Co-authored-by: saragluna <31124698+saragluna@users.noreply.github.com>
Addressed code review feedback to remove extra blank line before closing brace Co-authored-by: saragluna <31124698+saragluna@users.noreply.github.com>
… creation Addressed code review feedback to avoid anonymous inner class memory leak by using explicit HashMap creation instead of double-brace initialization Co-authored-by: saragluna <31124698+saragluna@users.noreply.github.com>
Allow users to inject a custom RetryTemplate from Spring context via setRetryTemplate() method. When provided, the custom template takes precedence over the auto-created one from consumer properties. Changes: - Added retryTemplate field to ServiceBusMessageChannelBinder - Added setRetryTemplate() setter method - Modified createConsumerEndpoint to use injected template if available - Added test to verify custom RetryTemplate is used - Updated documentation with custom RetryTemplate example - Updated CHANGELOG with new feature Co-authored-by: saragluna <31124698+saragluna@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@saragluna could we get an update on this one please? |
|
Hi @copilot. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days. |
1 similar comment
|
Hi @copilot. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days. |
There was a problem hiding this comment.
Pull request overview
This PR updates the Spring Cloud Azure Service Bus Stream Binder to honor Spring Cloud Stream’s standard consumer retry/backoff properties by wiring a RetryTemplate into inbound message dispatch.
Changes:
- Add optional retry execution around inbound message handling in
ServiceBusInboundChannelAdapter. - Build a
RetryTemplateinServiceBusMessageChannelBinderfrom Spring Cloud Stream consumer properties (or allow injecting a custom template). - Add docs/tests covering the new retry configuration behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/spring/spring-integration-azure-servicebus/src/main/java/com/azure/spring/integration/servicebus/inbound/ServiceBusInboundChannelAdapter.java | Adds RetryTemplate support and wraps sendMessage() in retry execution. |
| sdk/spring/spring-integration-azure-servicebus/CHANGELOG.md | Notes the new retry template setter on the inbound adapter. |
| sdk/spring/spring-cloud-azure-stream-binder-servicebus/src/main/java/com/azure/spring/cloud/stream/binder/servicebus/implementation/ServiceBusMessageChannelBinder.java | Creates/configures retry based on consumer properties and supports injecting a custom RetryTemplate. |
| sdk/spring/spring-cloud-azure-stream-binder-servicebus/src/test/java/com/azure/spring/cloud/stream/binder/servicebus/implementation/ServiceBusRetryTest.java | Adds unit tests for retry template presence and custom template injection. |
| sdk/spring/spring-cloud-azure-stream-binder-servicebus/RETRY_CONFIGURATION.md | Adds end-user documentation for retry/backoff properties and custom template injection. |
| sdk/spring/spring-cloud-azure-stream-binder-servicebus/CHANGELOG.md | Notes support for Spring Cloud Stream retry properties and the binder retry template setter. |
|
@copilot apply changes based on the comments in this thread |
…rtion - Add getRetryTemplate() public getter to ServiceBusMessageChannelBinder, matching the same pattern as the existing getter on ServiceBusInboundChannelAdapter. - Update retryTemplateShouldBeWiredWhenBeanProvided in ServiceBusBinderConfigurationTests to use binder.getRetryTemplate() instead of ReflectionTestUtils.getField(binder, "retryTemplate"), removing brittle reflection and validating via the public API. Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-java/sessions/4132c8e7-88bb-48bc-b279-64842bd4a0fd Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
Done in commit |
|
@copilot apply changes based on the comments in this thread |
|
@rujche Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub. You can ask me to try again later by mentioning me in a new comment. If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: Sorry for the inconvenience! |
|
@copilot the command you issued was incorrect. Please try again. Examples are: and |
…retry tests
1. ServiceBusInboundChannelAdapter.sendMessageDirectly(): replace
outputCh.send(message) with getMessagingTemplate().send(outputCh, message)
so the adapter's configured sendTimeout is respected and
MessageDeliveryException is still propagated to the RetryTemplate.
2. ServiceBusMessageChannelBinder: extract createExponentialBackOffPolicy()
from createRetryTemplate() as a package-private method so tests can call
it directly without reflecting into RetryTemplate internals.
3. ServiceBusRetryTest: replace ReflectionTestUtils.getField(retryTemplate,
"backOffPolicy") with binder.createExponentialBackOffPolicy(properties).
Remove now-unused ReflectionTestUtils import.
4. ServiceBusInboundChannelAdapterTests: add two tests for the retry-
exhausted path:
- retryTemplateExhaustedWithErrorChannelRoutesToErrorChannel: verify
exactly one error message is routed to the error channel
- retryTemplateExhaustedWithoutErrorChannelRethrowsException: verify
the exception propagates when no error channel is configured
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-java/sessions/c903f27e-667e-4021-bda8-1a187b34fd8d
Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
Done in commit
|
|
@copilot apply changes based on the comments in this thread |
…in teardown 1. ServiceBusInboundChannelAdapter.sendMessageDirectly(): remove the redundant try/catch that just re-threw MessageDeliveryException. getMessagingTemplate().send() already propagates the exception; the extra wrapping added noise without any behavioral change. 2. ServiceBusRetryTest: move binder construction from final field init into @beforeeach so each test gets a fresh, unmodified instance. State mutations like binder.setRetryTemplate() in one test can no longer leak into subsequent tests regardless of execution order. 3. ServiceBusRetryTest: store the GenericApplicationContext as a field and close it in @AfterEach to avoid resource leaks between test runs. Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-java/sessions/4c3bfec8-0052-463c-9096-b899cad6c134 Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
Done in commit a123343. Applied all three comments:
|
|
@copilot apply changes based on the comments in this thread |
1. ServiceBusInboundChannelAdapter: remove unused MessageDeliveryException import (the try/catch that used it was removed in a prior commit). 2. ServiceBusBinderConfiguration: qualify the ObjectProvider<RetryTemplate> parameter with @qualifier("serviceBusRetryTemplate") so the binder only picks up a bean explicitly named serviceBusRetryTemplate. This prevents NoUniqueBeanDefinitionException in apps that define multiple RetryTemplate beans and documents the injection contract clearly. 3. Update Javadoc for the retryTemplate parameter to state the required bean name. 4. ServiceBusBinderConfigurationTests: register the test bean under the name "serviceBusRetryTemplate" to match the new qualifier requirement. Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-java/sessions/d9cff3b9-7add-4fd3-8995-126b2ff4d69c Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
Done in commit
|
|
@copilot resolve the merge conflicts in this pull request |
Resolve merge conflict in sdk/spring/CHANGELOG.md: - Keep the Spring Cloud Azure Autoconfigure section (from main) with the passwordless JDBC/Redis scope bug fix - Keep the Spring Cloud Azure Stream Binder Service Bus section (from our branch) with the retry feature entries - Drop the empty ### Breaking Changes / ### Bugs Fixed / ### Other Changes placeholders that main replaced with module-specific sections Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-java/sessions/1db09201-c1f0-47e3-945e-eeb46180d259 Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
Done. Merged |
|
@copilot resolve the merge conflicts in this pull request |
…ries Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
Done in commit |
This pull request adds robust retry support for message processing failures in the
spring-cloud-azure-stream-binder-servicebusmodule. It introduces support for Spring Cloud Stream consumer retry properties (such asmaxAttempts,backOffInitialInterval,backOffMaxInterval, andbackOffMultiplier), enables exponential backoff for retries, and allows injection of a customRetryTemplatefor advanced scenarios. The changes also include comprehensive tests to verify the new retry logic and its configurability.New Retry Support for Service Bus Stream Binder:
Feature Additions:
maxAttempts,backOffInitialInterval,backOffMaxInterval,backOffMultiplier) for exponential backoff [1]], [2]], [3]]).RetryTemplatebean (namedserviceBusRetryTemplate) for advanced retry scenarios [1]], [2]], [3]], [4]]).Dependency Updates:
spring-retrydependency to the module and updated the dependency management and banned dependencies configuration [1]], [2]]).Configuration and Integration:
RetryTemplatebean into theServiceBusMessageChannelBinder[1]], [2]]).Test Coverage:
maxAttemptsis 1 [1]], [2]]).These enhancements provide more reliable and configurable message processing for Service Bus consumers, supporting both standard and advanced retry scenarios.